import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.awt.image.MemoryImageSource;

public class Game {
    static BufferedImage airimg;
    static BufferedImage bigimg;
    static BufferedImage[] extimg = new BufferedImage[3];
    static BufferedImage[] heroimg = new BufferedImage[2];
    static BufferedImage background,startmenu,pusemenu,endmenu;
    static Image transqarentcursor;//透明光标
    static BufferedImage[] airboom = new BufferedImage[4];
    static BufferedImage[] bigboom = new BufferedImage[4];
    static BufferedImage[] heroboom = new BufferedImage[4];
    static BufferedImage[] extboom = new BufferedImage[6];
    static BufferedImage[] beeimg = new BufferedImage[5];
    static {
        background = PlayPanel.readImage("img/background.png");
        startmenu = PlayPanel.readImage("img/start.png");
        pusemenu = PlayPanel.readImage("img/pause.png");
        endmenu = PlayPanel.readImage("img/gameover.png");
        transqarentcursor = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(0, 0, new int[0], 0, 0));
        airimg = PlayPanel.readImage("img/airplane.png");
        bigimg = PlayPanel.readImage("img/bigplane.png");
        extimg[0] = PlayPanel.readImage("img/extraplane_n1.png");
        extimg[1] = PlayPanel.readImage("img/extraplane_n2.png");
        extimg[2] = PlayPanel.readImage("img/extraplane_hit.png");
        heroimg[0] = PlayPanel.readImage("img/hero0.png");
        heroimg[1] = PlayPanel.readImage("img/hero1.png");
        for (int i = 0; i < 4; i++) {
            airboom[i] = PlayPanel.readImage("img/airplane_ember"+i+".png");
            bigboom[i] = PlayPanel.readImage("img/bigplane_ember"+i+".png");
            heroboom[i] = PlayPanel.readImage("img/hero_ember"+i+".png");
            extboom[i] = PlayPanel.readImage("img/extraplane_ember"+i+".png");
            beeimg[i+1] = PlayPanel.readImage("img/bee_ember"+i+".png");
        }
        extboom[4] = PlayPanel.readImage("img/extraplane_ember4.png");
        extboom[5] = PlayPanel.readImage("img/extraplane_ember5.png");
        beeimg[0] = PlayPanel.readImage("img/bee_ember0.png");
    }


    public static void main(String[] args) {
        JFrame win = new JFrame();
        PlayPanel pan = new PlayPanel();


        win.setSize(StaticNumber.WINWID,StaticNumber.WINHIG);
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        win.setLocationRelativeTo(null);
        win.setAlwaysOnTop(true);
//        win.setUndecorated(true);

        win.add(pan);

        win.setVisible(true);

        pan.action();

        MouseAdapter adapter = new MouseAdapter() {
            @Override//点击
            public void mouseClicked(MouseEvent e) {
                //如果游戏在准备界面，点击屏幕开始游戏
                if (PlayPanel.getGamemode() == 0) {

                    HeroPlane.getHeroplane().setX(e.getX()-49);
                    HeroPlane.getHeroplane().setY(e.getY()-62);
                    PlayPanel.setGamemode(1);

                }
                else if (PlayPanel.getGamemode() == 1) {
//            gamemode = 2;
                    PlayPanel.setGamemode(3);
                }

                //如果游戏在死亡界面，点击屏幕进入准备界面
                else if (PlayPanel.getGamemode() == 2) {
                    PlayPanel.clear();
                    PlayPanel.setGamemode(0);

                }


                else if (PlayPanel.getGamemode() == 3){
                    PlayPanel.setGamemode(1);
                }
                pan.repaint();
            }

            @Override//移动
            public void mouseMoved(MouseEvent e) {
                if (PlayPanel.getGamemode() == 1&&HeroPlane.getHeroplane()!=null){

                    HeroPlane.getHeroplane().setX(e.getX()-49);
                    HeroPlane.getHeroplane().setY(e.getY()-62);
                }
                pan.repaint();
            }

//            @Override//进入窗口
//            public void mouseEntered(MouseEvent e) {
//            if (gamemode == 3) gamemode = 1;
//            }
//
//            @Override//移出窗口
//            public void mouseExited(MouseEvent e) {
//                if (gamemode == 1) {
//                    gamemode = 3;
//                }
//            }
        };

        win.addMouseListener(adapter);
        win.addMouseMotionListener(adapter);


    }
}
